#include <cstdio>
using namespace std;
typedef long long ll;
int i,j,k,n,m,x,y,t;
int a[11],b[11];
ll ans,M[11],inv1,inv2;
void exgcd(ll n,ll m,ll &x,ll &y){
    if (m==0){x=1;y=0;return ;}
    exgcd(m,n%m,x,y);
    int xx=y,yy=x-(n/m)*xx;
    x=xx;y=yy;
}
int main(){
    scanf("%d",&n);M[0]=1;
    for (i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]),M[0]*=a[i];
    for (i=1;i<=n;i++)M[i]=M[0]/a[i];
    for (i=1;i<=n;i++){
        exgcd(M[i],a[i],inv1,inv2);
        if (inv1<0)inv1+=a[i];
        // printf("%lld %d %lld %lld\n",inv1,a[i],M[i],1ll*b[i]*M[i]*inv1);
        ans=(ans+1ll*b[i]*M[i]*inv1%M[0])%M[0];
    }
    printf("%lld\n",ans);
    return 0;
}